<?php

require PATH_MODELS . 'MenuModel.class.php';

/**
 * 页面跳转
 */
class LoginPage extends BasePage {

    private $M;
    private $way = '';

    function __construct() {
        $this->M = new MenuModel();
        $this->way = isset($_GET['way']) ? trim($_GET['way']) : '';
        parent::getMenuList($this->M);
    }

    /**
      +-------------------------------------------------------------------------
     * 获取验证码
      +-------------------------------------------------------------------------
     * @copyright (c) 2013-03, 崔俊涛
      +-------------------------------------------------------------------------
     */
    function getCode() {
        $code_name = isset($_GET['code_name']) ? trim($_GET['code_name']) : '';
        if (!empty($code_name)) {
            $verify = new ExtendsYspVerifyCode(DOMAIN_NAME, $code_name);
            $verify->getAuthImage();
        }
    }

//    欢迎页
    function index() {
        parent::checkUserLogin();
        include PATH_VIEWS . 'login/welcome.php';
    }

//    登陆页
    function login() {
        include PATH_VIEWS . 'login/login.php';
    }

    /**
      +-------------------------------------------------------------------------
     * 消息提示页
      +-------------------------------------------------------------------------
     * @copyright 
      +-------------------------------------------------------------------------
     */
    function msgInfo() {
        parent::getMenuList($this->M);
        include PATH_VIEWS . 'common/msg_info.php';
    }

//    用户登录检测
    function usreLogin() {
        $usre = isset($_POST['userName']) ? trim($_POST['userName']) : '';
        $password = isset($_POST['passWord']) ? md5(trim($_POST['passWord'])) : '';
        $verify_code = isset($_POST['verifyCode']) ? trim($_POST['verifyCode']) : '';
//        if ($verify_code != $_SESSION["verification"]) {
//            echo '对不起，验证码输入有误！';
//            exit;
//            //parent::getMsg('验证码错误！', false);
//        }
        $info = $this->M->getOneRow('tb_usre', 'Fid,Fname,Faccount', "WHERE (Faccount='{$usre}' AND Fpassword='$password')");
       // print_r($info);exit;
        if (!isset($info['Fid'])) {
            echo '0|对不起，您输入的登录信息有误，请重新输入。';
            return FALSE;
        } else {

            //更新最后登录时间和随机码
            $data_update = array(
                'FlastTime' => time()
            );
            $this->M->Update('tb_usre', $data_update, "WHERE Fid={$info['Fid']}");
            $_SESSION['admin']['id'] = $info['Fid'];
            $_SESSION['admin']['Faccount'] = $info['Faccount'];
            $_SESSION['admin']['name'] = $info['Fname'];
            $_SESSION['admin']['loginTime'] = time();
//         登录成功状态
            echo 1;
        }
    }

    /**
      +-------------------------------------------------------------------------
     * 退出登录
      +-------------------------------------------------------------------------
     */
    function loginOut() {
      unset($_SESSION['admin']);
        //跳转到登录页面
        header('location: ' . DOMAIN_NAME_ADMIN);
    }

}
